var db = require( '../db/db' );

const tableName = 'core.plan';

exports.getAll = async function ( userId ) {
    var sql = `select * from ${ tableName }`;

    try {

        var result = await db.runSql( sql, null );

        if ( result ) {
            return result.rows;
        }
        return null;

    } catch ( e ) {
        console.error( "查询方案信息出错" );
        return null;
    }
}

exports.getByName = async function ( name ) {
    var sql = `select * from ${ tableName } where name=$1 limit 1`;
    var params = [ name ];

    try {

        var result = await db.runSql( sql, params );

        if ( result ) {
            return result.rows;
        }
        return null;

    } catch ( e ) {
        console.error( "查询方案信息出错" );
        return null;
    }
}